<html>
<head><meta charset="utf-8"><title>fn/pointer structural equality · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html">fn/pointer structural equality</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="235061162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061162">(Apr 18 2021 at 10:12)</a>:</h4>
<p>I was looking at <a href="https://github.com/rust-lang/rust/issues/84238">#84238</a> about [fn(); N] being allowed as a const param type and it seems like <code>StructuralEq</code> gets derived for structs containing fn/pointers too. Do you know if this is correct <span class="user-mention" data-user-id="120791">@RalfJ</span> ?<br>
<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=80bc6e1ca25e1f45d76e8012be846d32">playground</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics, structural_match)]</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span><span class="n">core</span>::<span class="n">marker</span>::<span class="n">StructuralEq</span><span class="p">;</span><span class="w"></span>

<span class="cp">#[derive(Eq, PartialEq)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="p">(</span><span class="k">fn</span><span class="p">());</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">StructuralEq</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span>::<span class="o">&lt;</span><span class="n">Foo</span><span class="o">&gt;</span><span class="p">();</span><span class="w"> </span><span class="c1">// &lt;- ?? no compile error</span>
<span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">B</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">F</span>: <span class="nc">Foo</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="235061693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061693">(Apr 18 2021 at 10:22)</a>:</h4>
<p>I think this is not correct</p>



<a name="235061697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061697">(Apr 18 2021 at 10:22)</a>:</h4>
<p>but <code>StructuralEq</code> is a poorly defined mess currently^^</p>



<a name="235061702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061702">(Apr 18 2021 at 10:22)</a>:</h4>
<p>I think it's what's causing that const generics issue</p>



<a name="235061712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061712">(Apr 18 2021 at 10:22)</a>:</h4>
<p>see <a href="https://github.com/rust-lang/rust/issues/74446">https://github.com/rust-lang/rust/issues/74446</a></p>



<a name="235061715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061715">(Apr 18 2021 at 10:22)</a>:</h4>
<p>ahhh yes I remember seeing this issue lol</p>



<a name="235061718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061718">(Apr 18 2021 at 10:23)</a>:</h4>
<p>yeah that seems likely</p>



<a name="235061743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061743">(Apr 18 2021 at 10:23)</a>:</h4>
<p>well there's 2 issues:</p>
<ul>
<li>we should really ICE or error when using fn ptrs in const generics (concretely: when constructing a valtree for something involving fn ptrs), but currently these sanity checks are missing (because we are not constructing these valtrees yet)</li>
<li>we incorrectly classify fn ptrs as having structural eq -- at least I think it's incorrect, but since structural eq is not properly defined this is hard to tell</li>
</ul>



<a name="235061829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061829">(Apr 18 2021 at 10:25)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> has some WIP patch for valtrees: <a href="https://github.com/rust-lang/rust/pull/83234">https://github.com/rust-lang/rust/pull/83234</a>. I <em>think</em> that would turn the fn ptrs array into an ICE or error, which is better than the current behavior.</p>



<a name="235061953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235061953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235061953">(Apr 18 2021 at 10:27)</a>:</h4>
<p>specifically, <a href="https://github.com/rust-lang/rust/pull/83234/files#diff-5809d5770c4c639b699be36651c1e8942ce7aa946dac2657f4fe08895e605b09R100">here</a> we refuse to create a valtree for values involving fn ptrs -- not sure what that <code>None</code> turns into later when a valtree is required due to a const being used as a generic</p>



<a name="235071283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235071283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235071283">(Apr 18 2021 at 13:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/fn.2Fpointer.20structural.20equality/near/235061743">said</a>:</p>
<blockquote>
<p>well there's 2 issues:</p>
<ul>
<li>we should really ICE or error when using fn ptrs in const generics (concretely: when constructing a valtree for something involving fn ptrs), but currently these sanity checks are missing (because we are not constructing these valtrees yet)</li>
<li>we incorrectly classify fn ptrs as having structural eq -- at least I think it's incorrect, but since structural eq is not properly defined this is hard to tell</li>
</ul>
</blockquote>
<p>This makes sense to me <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> we could really do with defining structural eq better, const generics seems to care about it <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="235071791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/fn/pointer%20structural%20equality/near/235071791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/fn.2Fpointer.20structural.20equality.html#235071791">(Apr 18 2021 at 13:22)</a>:</h4>
<p>Yea, valtree construction returning None means not structurally eq</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>